// ParameterDialog.cpp : implementation file
//

#include "stdafx.h"
#include "test.h"
#include "ParameterDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CParameterDialog dialog


CParameterDialog::CParameterDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CParameterDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CParameterDialog)
	m_bTexturas = FALSE;
	m_bAliasFog = FALSE;
	m_bAliasLine = FALSE;
	m_bAliasPoint = FALSE;
	m_bAliasPoly = FALSE;
	m_bCull = FALSE;
	m_filter = -1;
	m_fog = -1;
	m_ligtFlat = -1;
	m_lineWidth = 0;
	m_bLocalViewer = FALSE;
	m_bPersp = FALSE;
	m_renderPoints = -1;
	m_fogValue = 0.0f;
	//}}AFX_DATA_INIT
}


void CParameterDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CParameterDialog)
	DDX_Check(pDX, ID_MOSTRAR_TEXTURAS, m_bTexturas);
	DDX_Check(pDX, IDC_ANTIALIAS_FOG, m_bAliasFog);
	DDX_Check(pDX, IDC_ANTIALIAS_LINES, m_bAliasLine);
	DDX_Check(pDX, IDC_ANTIALIAS_POINTS, m_bAliasPoint);
	DDX_Check(pDX, IDC_ANTIALIAS_POLYGON, m_bAliasPoly);
	DDX_Check(pDX, IDC_CULLBACKFACES, m_bCull);
	DDX_Radio(pDX, IDC_FILTER_NONE, m_filter);
	DDX_Radio(pDX, IDC_FOG_NONE, m_fog);
	DDX_Radio(pDX, IDC_LIGHT_FLAT, m_ligtFlat);
	DDX_Text(pDX, IDC_LINEWIDTH, m_lineWidth);
	DDX_Check(pDX, IDC_LOCAL_VIEWER, m_bLocalViewer);
	DDX_Check(pDX, IDC_PERSPECTIVECORRECTION, m_bPersp);
	DDX_Radio(pDX, IDC_RENDER_POINTS, m_renderPoints);
	DDX_Text(pDX, IDC_FOG_VALUE, m_fogValue);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CParameterDialog, CDialog)
	//{{AFX_MSG_MAP(CParameterDialog)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CParameterDialog message handlers

void CParameterDialog::setEngineCaps(EngineCaps caps)
{

	switch(caps.lightingType){
	case EngineCaps::FLAT: m_ligtFlat=0; break;
	case EngineCaps::PHONG: m_ligtFlat=1; break;
	case EngineCaps::GOURAUD: m_ligtFlat=2; break;
	default:  break;
	}

	if(caps.texturing)
		m_bTexturas=TRUE;
	else
		m_bTexturas=FALSE;

	if(caps.cullBackFaces)
		m_bCull=TRUE;
	else
		m_bCull=FALSE;
	

	switch(caps.renderType){
	case EngineCaps::RENDER_LINES: m_renderPoints=1; break;
	case EngineCaps::RENDER_POINTS:	m_renderPoints=0; break;
	case EngineCaps::RENDER_POLYGONS: m_renderPoints=2; break;
	}


	if(caps.localViewer)
		m_bLocalViewer=TRUE;
	else
		m_bLocalViewer=FALSE;

	switch(caps.fogType){
	case EngineCaps::NO_FOG: m_fog=0; break;
	case EngineCaps::LINEAR_FOG: m_fog=1; break;
	case EngineCaps::QUADRATIC_FOG: m_fog=2; break;
	}
	m_lineWidth=caps.lineWidth;
	m_fogValue=caps.fogParam;
	m_filter=0;
	if(caps.perspectiveCorrection)
		m_bPersp=TRUE;
	else
		m_bPersp=FALSE;

	m_bAliasFog=FALSE;
	m_bAliasLine=FALSE;
	m_bAliasPoint=FALSE;
	m_bAliasPoly=FALSE;
	
}

EngineCaps CParameterDialog::getEngineCaps()
{
	EngineCaps caps;

	switch(m_ligtFlat){
	case 0: caps.lightingType=EngineCaps::FLAT; break;
	case 1: caps.lightingType=EngineCaps::PHONG;  break;
	case 2: caps.lightingType=EngineCaps::GOURAUD; break;
	default:  break;
	}

	if(m_bTexturas)
		caps.texturing=true;
	else
		caps.texturing=false;

	if(m_bCull)
		caps.cullBackFaces=true;
	else
		caps.cullBackFaces=false;
	

	switch(m_renderPoints){
	case 1:caps.renderType=EngineCaps::RENDER_LINES; break;
	case 0:caps.renderType=EngineCaps::RENDER_POINTS; break;
	case 2:caps.renderType=EngineCaps::RENDER_POLYGONS; break;
	}


	if(m_bLocalViewer)
		caps.localViewer=true;
	else
		caps.localViewer=false;

	switch(m_fog){
	case 0:caps.fogType=EngineCaps::NO_FOG; break;
	case 1:caps.fogType=EngineCaps::LINEAR_FOG; break;
	case 2:caps.fogType=EngineCaps::QUADRATIC_FOG; break;
	}

	caps.lineWidth=m_lineWidth;
	caps.fogParam=m_fogValue;
	

	if(m_bPersp)
		caps.perspectiveCorrection=true;
	else
		caps.perspectiveCorrection=false;

	return caps;
}

